

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>1. Tutorial &mdash; Documentation of EZ-Draw 1.2</title>
    
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../../share/ez-style-1.2.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="Documentation of EZ-Draw 1.2" href="index.html" />
    <link rel="next" title="2. Reference manual" href="ez-reference.html" />
    <link rel="prev" title="EZ-Draw, to draw in C" href="ez-manual.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <span class="current">English</span></li>
        <li class="right">
          <a href="../../fr/html/ez-tutorial.html">Français</a> |</li>
        <li><a href="../../../index-en.html">EZ-Draw 1.2</a> &raquo;</li>
        <li><a href="ez-manual.html">Documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="tutorial">
<span id="chap-tutorial"></span><h1>1. Tutorial<a class="headerlink" href="#tutorial" title="Permalink to this headline">¶</a></h1>
<p>The easiest way to proceed is to work directly in the EZ-Draw directory,
starting from an example, and to complete the provided <a class="reference external" href="../../../Makefile">Makefile</a>,
see section <a class="reference internal" href="#sec-tut-compilation"><em>Compilation</em></a>.</p>
<div class="section" id="first-program-with-a-window">
<span id="sec-tut-first-prog"></span><span id="index-0"></span><h2>1.1. First program with a window<a class="headerlink" href="#first-program-with-a-window" title="Permalink to this headline">¶</a></h2>
<p>Let us write our first program that opens a window, and name it <tt class="docutils literal"><span class="pre">demo-01.c</span></tt>.
We first include <a class="reference external" href="../../../ez-draw.h">ez-draw.h</a> (line 1, see below):
this file defines the types and prototypes of the main EZ-Draw module,
and it also includes the standard headers such as <tt class="docutils literal"><span class="pre">&lt;stdio.h&gt;</span></tt>, <tt class="docutils literal"><span class="pre">&lt;stdlib.h&gt;</span></tt>,
<tt class="docutils literal"><span class="pre">&lt;string.h&gt;</span></tt>, so we don&#8217;t need to worry about.</p>
<p>In <tt class="docutils literal"><span class="pre">main</span></tt>, we initialize the module and the graphic mode by calling
<a class="reference internal" href="ez-reference.html#c.ez_init" title="ez_init"><tt class="xref c c-func docutils literal"><span class="pre">ez_init()</span></tt></a>; if the initialization fails, the function print
an error message in the terminal, then return -1.
In this case, we must terminate the program by <tt class="docutils literal"><span class="pre">exit(1)</span></tt> .</p>
<p>Next we create one (or several) window(s) using function
<a class="reference internal" href="ez-reference.html#c.ez_window_create" title="ez_window_create"><tt class="xref c c-func docutils literal"><span class="pre">ez_window_create()</span></tt></a>. These windows are displayed when the program
reaches <a class="reference internal" href="ez-reference.html#c.ez_main_loop" title="ez_main_loop"><tt class="xref c c-func docutils literal"><span class="pre">ez_main_loop()</span></tt></a>: that is this function which &#8220;gives life&#8221; to the
windows. It stops when one calls <a class="reference internal" href="ez-reference.html#c.ez_quit" title="ez_quit"><tt class="xref c c-func docutils literal"><span class="pre">ez_quit()</span></tt></a>, or when all windows are
destroyed.</p>
<p>Here is the file <a class="reference external" href="../../../demo-01.c">demo-01.c</a> :</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="s">&quot;Demo 01: Hello World&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-01" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-01.png" />
</div>
</div>
<div class="section" id="compilation">
<span id="sec-tut-compilation"></span><span id="index-1"></span><h2>1.2. Compilation<a class="headerlink" href="#compilation" title="Permalink to this headline">¶</a></h2>
<p>To compile <tt class="docutils literal"><span class="pre">demo-01.c</span></tt> in a terminal on Unix, type</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">gcc -Wall demo-01.c ez-draw.c -o demo-01 -lX11 -lXext</span>
</pre></div>
</div>
<p>or on Windows, type</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">gcc -Wall demo-01.c ez-draw.c -o demo-01.exe -lgdi32</span>
</pre></div>
</div>
<p>To run the program in a terminal on Unix, type</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">./demo-01</span>
</pre></div>
</div>
<p>or on Windows, type</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">demo-01</span>
</pre></div>
</div>
<p id="index-2"><img alt="bullet" src="_images/pinkball.gif" /> It is more handy to use the command <tt class="docutils literal"><span class="pre">make</span></tt> instead of typing over
and over the <tt class="docutils literal"><span class="pre">gcc</span></tt> command line.
The command <tt class="docutils literal"><span class="pre">make</span></tt> use the same <a class="reference external" href="../../../Makefile">Makefile</a> on Unix and on Windows.</p>
<p>To compile everything the first time, or to compile again the modified C files,
it is sufficient to type in the terminal, whichever your system is:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">make all</span>
</pre></div>
</div>
<p>On error, see chapter <a class="reference external" href="ez-install.html">Installation</a>.
If everything is up to date, <tt class="docutils literal"><span class="pre">make</span></tt> will display:
<tt class="docutils literal"><span class="pre">make:</span> <span class="pre">Nothing</span> <span class="pre">to</span> <span class="pre">be</span> <span class="pre">done</span> <span class="pre">for</span> <span class="pre">`all'.</span></tt>
You can always force a general re-compilation by typing:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">make clean all</span>
</pre></div>
</div>
<p>Finally if you want to clean your directory, for instance before making
a backup, type:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">make distclean</span>
</pre></div>
</div>
<p>This will erase all executable and temporary files, and will keep only the
source files.</p>
<dl class="docutils">
<dt><em>Exercise :</em></dt>
<dd>Edit the file <tt class="docutils literal"><span class="pre">demo-01.c</span></tt>, and change the title with
<tt class="docutils literal"><span class="pre">&quot;My</span> <span class="pre">first</span> <span class="pre">program&quot;</span></tt>. Compile with <tt class="docutils literal"><span class="pre">make</span></tt> then run the program.</dd>
</dl>
<p><img alt="bullet" src="_images/pinkball.gif" /> Let us see now how to add a new program. Just edit the file
<a class="reference external" href="../../../Makefile">Makefile</a> , and add in section C the name of the executable in the list
<tt class="docutils literal"><span class="pre">EXECS</span></tt>, <tt class="docutils literal"><span class="pre">EXECS_M</span></tt> or <tt class="docutils literal"><span class="pre">EXECS_IM</span></tt>, then save.
We can then type <tt class="docutils literal"><span class="pre">make</span> <span class="pre">all</span></tt> to compile the new program.
There are several lists to distinguish between cases:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">EXECS</span></tt> : to compile only with <a class="reference external" href="../../../ez-draw.c">ez-draw.c</a> ;</li>
<li><tt class="docutils literal"><span class="pre">EXECS_M</span></tt> : to compile with <a class="reference external" href="../../../ez-draw.c">ez-draw.c</a> and <tt class="docutils literal"><span class="pre">-lm</span></tt> (the math library);</li>
<li><tt class="docutils literal"><span class="pre">EXECS_IM</span></tt> : to compile with <a class="reference external" href="../../../ez-draw.c">ez-draw.c</a>, <tt class="docutils literal"><span class="pre">-lm</span></tt> and <a class="reference external" href="../../../ez-image.c">ez-image.c</a> (to display images).</li>
</ul>
<p>Here are the current lists in the <a class="reference external" href="../../../Makefile">Makefile</a> :</p>
<div class="highlight-makefile"><div class="highlight"><pre><span class="nv">EXECS</span> <span class="o">=</span> demo-01 demo-02 demo-03 demo-04 demo-05 demo-06 demo-07 demo-08 <span class="se">\</span>
        demo-09 demo-11 jeu-sudoku jeu-nim jeu-vie jeu-taquin jeu-2048 <span class="se">\</span>
        jeu-tetris

<span class="nv">EXECS_M</span> <span class="o">=</span> demo-10 jeu-laby jeu-ezen jeu-heziom jeu-tangram

<span class="nv">EXECS_IM</span> <span class="o">=</span> demo-12 demo-13 demo-14 demo-15 demo-16 demo-17 <span class="se">\</span>
</pre></div>
</div>
<p>As you can see, when a list is on several lines, the intermediary lines
are ended by a <tt class="docutils literal"><span class="pre">\</span></tt>.</p>
<dl class="docutils">
<dt><em>Exercise :</em></dt>
<dd>Copy the file <tt class="docutils literal"><span class="pre">demo-01.c</span></tt> as <tt class="docutils literal"><span class="pre">trial1.c</span></tt>, and add
<tt class="docutils literal"><span class="pre">trial1</span></tt> in the <a class="reference external" href="../../../Makefile">Makefile</a>.
Compile with <tt class="docutils literal"><span class="pre">make</span></tt> then run the program.</dd>
</dl>
<p><img alt="bullet" src="_images/pinkball.gif" /> You can use the provided <a class="reference external" href="../../../Makefile">Makefile</a> for more advanced projects
divided in several modules. Suppose that your executable is named <tt class="docutils literal"><span class="pre">myappli</span></tt>,
that your project uses the modules <tt class="docutils literal"><span class="pre">ez-draw.c</span></tt>, <tt class="docutils literal"><span class="pre">ez-image.c</span></tt>, <tt class="docutils literal"><span class="pre">myprog.c</span></tt>
and <tt class="docutils literal"><span class="pre">misc.c</span></tt>, and that you need the libraries <tt class="docutils literal"><span class="pre">-lm</span></tt> and <tt class="docutils literal"><span class="pre">-lgomp</span></tt>.
You just have to complete the fields <tt class="docutils literal"><span class="pre">EXECS_PRO</span></tt>, <tt class="docutils literal"><span class="pre">OBJS_PRO</span></tt> and
<tt class="docutils literal"><span class="pre">LIBS_PRO</span></tt>  in the <a class="reference external" href="../../../Makefile">Makefile</a> section D like that:</p>
<div class="highlight-makefile"><div class="highlight"><pre><span class="nv">EXECS_PRO</span> <span class="o">=</span> myappli
<span class="nv">OBJS_PRO</span>  <span class="o">=</span> ez-draw.o ez-image.o myprog.o misc.o
<span class="nv">LIBS_PRO</span>  <span class="o">=</span> -lm -lgomp
</pre></div>
</div>
<p><img alt="bullet" src="_images/pinkball.gif" /> Finally, if you want to create your project in a new directory,
here are the files that you have to copy in it:</p>
<ul class="simple">
<li><a class="reference external" href="../../../ez-draw.h">ez-draw.h</a> and <a class="reference external" href="../../../ez-draw.c">ez-draw.c</a> (it is the basic module),</li>
<li><a class="reference external" href="../../../ez-image.h">ez-image.h</a> and <a class="reference external" href="../../../ez-image.c">ez-image.c</a> (if you plan to display images),</li>
<li><a class="reference external" href="../../../Makefile">Makefile</a> and <a class="reference external" href="../../../make.bat">make.bat</a>.</li>
</ul>
<p>Just clear the <tt class="docutils literal"><span class="pre">EXECS</span></tt> lists in the <a class="reference external" href="../../../Makefile">Makefile</a> and fill the necessary fields.</p>
</div>
<div class="section" id="event-handler">
<span id="sec-tut-event-handler"></span><span id="index-3"></span><h2>1.3. Event handler<a class="headerlink" href="#event-handler" title="Permalink to this headline">¶</a></h2>
<p>We will now take a look at the handling of events in the windows.</p>
<p>The parameters of the function <a class="reference internal" href="ez-reference.html#c.ez_window_create" title="ez_window_create"><tt class="xref c c-func docutils literal"><span class="pre">ez_window_create()</span></tt></a> which is
responsible of a window creation are:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="n">Ez_window</span> <span class="nf">ez_window_create</span> <span class="p">(</span><span class="kt">int</span> <span class="n">w</span><span class="p">,</span> <span class="kt">int</span> <span class="n">h</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">,</span> <span class="n">Ez_func</span> <span class="n">on_event</span><span class="p">);</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">w</span></tt> is the width of the interior of the window in pixels,
<tt class="docutils literal"><span class="pre">h</span></tt> is the height,
<tt class="docutils literal"><span class="pre">name</span></tt> is the window title;
<tt class="docutils literal"><span class="pre">on_event</span></tt> is the event handler of the window, see below.</p>
<p>The result of <a class="reference internal" href="ez-reference.html#c.ez_window_create" title="ez_window_create"><tt class="xref c c-func docutils literal"><span class="pre">ez_window_create()</span></tt></a> has type <a class="reference internal" href="ez-reference.html#c.Ez_window" title="Ez_window"><tt class="xref c c-type docutils literal"><span class="pre">Ez_window</span></tt></a>;
it is used to identify the window, and can be printed in the terminal
as an hexadecimal value:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="n">Ez_window</span> <span class="n">win1</span><span class="p">;</span>
<span class="n">win1</span> <span class="o">=</span> <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="s">&quot;Demo 0: Hello World&quot;</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
<span class="n">printf</span> <span class="p">(</span><span class="s">&quot;win1 = 0x%x</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">ez_window_get_id</span><span class="p">(</span><span class="n">win1</span><span class="p">));</span>
</pre></div>
</div>
<p>To be able to interact with the user (key press and release, mouse moves and
click, etc) we have to realize a so-called <em>event handling</em>;
that is why we give the function <tt class="docutils literal"><span class="pre">on_event</span></tt> as a fourth parameter of
<a class="reference internal" href="ez-reference.html#c.ez_window_create" title="ez_window_create"><tt class="xref c c-func docutils literal"><span class="pre">ez_window_create()</span></tt></a>.</p>
<p id="index-4">The event handler <tt class="docutils literal"><span class="pre">on_event</span></tt> (also named <em>callback</em>), is a function of
your program (or <tt class="docutils literal"><span class="pre">NULL</span></tt> as in example <tt class="docutils literal"><span class="pre">demo-01</span></tt>).
This function will be automatically called by <a class="reference internal" href="ez-reference.html#c.ez_main_loop" title="ez_main_loop"><tt class="xref c c-func docutils literal"><span class="pre">ez_main_loop()</span></tt></a>
for each event that involves the window.</p>
<p>The function <tt class="docutils literal"><span class="pre">on_event</span></tt> has the following prototype:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="kt">void</span> <span class="nf">on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">);</span>
</pre></div>
</div>
<p>The parameter <tt class="docutils literal"><span class="pre">ev</span></tt> is the address of a struct whose fields describe
the event; in particular, <tt class="docutils literal"><span class="pre">ev-&gt;win</span></tt> tells which window is involved.
The other fields are detailed in section <a class="reference internal" href="#sec-tut-all-events"><em>Tracing events</em></a>.</p>
<p>We study two events in the following example <a class="reference external" href="../../../demo-02.c">demo-02.c</a> :</p>
<ul class="simple">
<li>The window manager tells to your program if the windows must be redrawn
(the first time they appear, when another window is passing ahead, etc).
When this happens, an <tt class="docutils literal"><span class="pre">Expose</span></tt> event is generated and the event handler
is called. At this time you have to redraw the whole content of the window
<tt class="docutils literal"><span class="pre">ev-&gt;win</span></tt>.</li>
</ul>
<ul class="simple">
<li>When the user press a key, the <tt class="docutils literal"><span class="pre">KeyPress</span></tt> event is generated.
The key code is available in <tt class="docutils literal"><span class="pre">ev-&gt;key_sym</span></tt> (for <em>key symbol</em>).
Each key code is expressed as a constant prefixed by <tt class="docutils literal"><span class="pre">XK_</span></tt>,
for instance <tt class="docutils literal"><span class="pre">XK_q</span></tt> stands for the key &#8220;q&#8221;.</li>
</ul>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>                <span class="cm">/* Called by ez_main_loop() */</span>
<span class="p">{</span>                                                <span class="cm">/* for each event on win1   */</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>

        <span class="k">case</span> <span class="n">Expose</span> :                           <span class="cm">/* We must redraw everything */</span>
            <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_red</span><span class="p">);</span>
            <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_MC</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span> <span class="mi">150</span><span class="p">,</span> 
                <span class="s">&quot;To quit, press the key &#39;q&#39;, or click</span><span class="se">\n</span><span class="s">&quot;</span>
                <span class="s">&quot;on the Close button of the window&quot;</span><span class="p">);</span>
            <span class="k">break</span><span class="p">;</span>

        <span class="k">case</span> <span class="n">KeyPress</span> :                                 <span class="cm">/* A key was pressed */</span>
            <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">case</span> <span class="n">XK_q</span> : <span class="n">ez_quit</span> <span class="p">();</span> <span class="k">break</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="s">&quot;Demo 02: Window and events&quot;</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-02" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-02.png" />
</div>
<p>This example <a class="reference external" href="../../../demo-02.c">demo-02.c</a> is a first attempt to manage the events, using a big
<tt class="docutils literal"><span class="pre">switch</span></tt> into <tt class="docutils literal"><span class="pre">win1_on_event</span></tt>.
The drawback of this method is the rapid growing of the <tt class="docutils literal"><span class="pre">switch</span></tt> when
enhancing the program, leading the program potentially unreadable.
That is why it is better to split <tt class="docutils literal"><span class="pre">win1_on_event</span></tt> in functions
(still using a <tt class="docutils literal"><span class="pre">switch</span></tt>),
each of them being specialized for an event; we do it in the next section.</p>
</div>
<div class="section" id="drawings-and-colors">
<span id="sec-tut-drawings-colors"></span><span id="index-5"></span><h2>1.4. Drawings and colors<a class="headerlink" href="#drawings-and-colors" title="Permalink to this headline">¶</a></h2>
<p>As explained in the previous section, the <tt class="docutils literal"><span class="pre">Expose</span></tt> event
means that the whole content of the windows must be redrawn.
In the next example we redraw by calling <tt class="docutils literal"><span class="pre">win1_on_expose</span></tt>.
Note: for each <tt class="docutils literal"><span class="pre">Expose</span></tt> event, EZ-Draw empties the window
(with a white background) before passing the event to your program.</p>
<p>The list of drawings is given in section <a class="reference internal" href="ez-reference.html#sec-ref-drawings"><em>Drawings</em></a>.
The coordinates are relative to the Origin, which is the top left
corner inside the window; <tt class="docutils literal"><span class="pre">x</span></tt> goes to the right and <tt class="docutils literal"><span class="pre">y</span></tt> goes down.</p>
<p>The drawings are automatically cut by the window border, so that there
is no need to worry if a drawing fits or not.</p>
<p>The drawings are performed using the current thickness (1 pixel by default).
you can change the thickness with  <a class="reference internal" href="ez-reference.html#c.ez_set_thick" title="ez_set_thick"><tt class="xref c c-func docutils literal"><span class="pre">ez_set_thick()</span></tt></a>,
see <a class="reference internal" href="ez-reference.html#sec-ref-drawings"><em>Drawings</em></a>.</p>
<p>The drawings are done in the current color (black by default).
To change color, call  <a class="reference internal" href="ez-reference.html#c.ez_set_color" title="ez_set_color"><tt class="xref c c-func docutils literal"><span class="pre">ez_set_color()</span></tt></a> by giving it the color number.
Some colors are predefined:
<tt class="docutils literal"><span class="pre">ez_black</span></tt>, <tt class="docutils literal"><span class="pre">ez_white</span></tt>, <tt class="docutils literal"><span class="pre">ez_grey</span></tt>, <tt class="docutils literal"><span class="pre">ez_red</span></tt>, <tt class="docutils literal"><span class="pre">ez_green</span></tt>, <tt class="docutils literal"><span class="pre">ez_blue</span></tt>,
<tt class="docutils literal"><span class="pre">ez_yellow</span></tt>, <tt class="docutils literal"><span class="pre">ez_cyan</span></tt>, <tt class="docutils literal"><span class="pre">ez_magenta</span></tt>.
It is possible to create other colors, see <a class="reference internal" href="ez-reference.html#sec-ref-colors"><em>Colors</em></a>.</p>
<p>Here is the file <a class="reference external" href="../../../demo-03.c">demo-03.c</a> :</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>


<span class="kt">void</span> <span class="nf">win1_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_magenta</span><span class="p">);</span>
    <span class="n">ez_draw_text</span>      <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_BL</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="s">&quot;Thickness 1&quot;</span><span class="p">);</span>
    <span class="n">ez_set_thick</span> <span class="p">(</span><span class="mi">1</span><span class="p">);</span>
    <span class="n">ez_draw_point</span>     <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span>  <span class="mi">30</span><span class="p">,</span>  <span class="mi">50</span><span class="p">);</span>
    <span class="n">ez_draw_line</span>      <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span>  <span class="mi">60</span><span class="p">,</span>  <span class="mi">35</span><span class="p">,</span> <span class="mi">130</span><span class="p">,</span>  <span class="mi">70</span><span class="p">);</span>
    <span class="n">ez_draw_rectangle</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">160</span><span class="p">,</span>  <span class="mi">30</span><span class="p">,</span> <span class="mi">220</span><span class="p">,</span>  <span class="mi">70</span><span class="p">);</span>
    <span class="n">ez_draw_circle</span>    <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">240</span><span class="p">,</span>  <span class="mi">30</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span>  <span class="mi">70</span><span class="p">);</span>
    <span class="n">ez_draw_triangle</span>  <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">320</span><span class="p">,</span>  <span class="mi">30</span><span class="p">,</span> <span class="mi">380</span><span class="p">,</span>  <span class="mi">40</span><span class="p">,</span> <span class="mi">350</span><span class="p">,</span>  <span class="mi">70</span><span class="p">);</span>

    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_black</span><span class="p">);</span>
    <span class="n">ez_draw_text</span>      <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_BL</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="s">&quot;Thickness 2&quot;</span><span class="p">);</span>
    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_cyan</span><span class="p">);</span>
    <span class="n">ez_set_thick</span> <span class="p">(</span><span class="mi">2</span><span class="p">);</span>
    <span class="n">ez_draw_point</span>     <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span>  <span class="mi">30</span><span class="p">,</span> <span class="mi">130</span><span class="p">);</span>
    <span class="n">ez_draw_line</span>      <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span>  <span class="mi">60</span><span class="p">,</span> <span class="mi">115</span><span class="p">,</span> <span class="mi">130</span><span class="p">,</span> <span class="mi">150</span><span class="p">);</span>
    <span class="n">ez_draw_rectangle</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">160</span><span class="p">,</span> <span class="mi">110</span><span class="p">,</span> <span class="mi">220</span><span class="p">,</span> <span class="mi">150</span><span class="p">);</span>
    <span class="n">ez_draw_circle</span>    <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">240</span><span class="p">,</span> <span class="mi">110</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="mi">150</span><span class="p">);</span>
    <span class="n">ez_draw_triangle</span>  <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">320</span><span class="p">,</span> <span class="mi">110</span><span class="p">,</span> <span class="mi">380</span><span class="p">,</span> <span class="mi">120</span><span class="p">,</span> <span class="mi">350</span><span class="p">,</span> <span class="mi">150</span><span class="p">);</span>

    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_blue</span><span class="p">);</span>
    <span class="n">ez_draw_text</span>      <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_BL</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">180</span><span class="p">,</span> <span class="s">&quot;Thickness 9&quot;</span><span class="p">);</span>
    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_green</span><span class="p">);</span>
    <span class="n">ez_set_thick</span> <span class="p">(</span><span class="mi">9</span><span class="p">);</span>
    <span class="n">ez_draw_point</span>     <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span>  <span class="mi">30</span><span class="p">,</span> <span class="mi">210</span><span class="p">);</span>
    <span class="n">ez_draw_line</span>      <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span>  <span class="mi">60</span><span class="p">,</span> <span class="mi">195</span><span class="p">,</span> <span class="mi">130</span><span class="p">,</span> <span class="mi">230</span><span class="p">);</span>
    <span class="n">ez_draw_rectangle</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">160</span><span class="p">,</span> <span class="mi">190</span><span class="p">,</span> <span class="mi">220</span><span class="p">,</span> <span class="mi">230</span><span class="p">);</span>
    <span class="n">ez_draw_circle</span>    <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">240</span><span class="p">,</span> <span class="mi">190</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="mi">230</span><span class="p">);</span>
    <span class="n">ez_draw_triangle</span>  <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">320</span><span class="p">,</span> <span class="mi">190</span><span class="p">,</span> <span class="mi">380</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span> <span class="mi">350</span><span class="p">,</span> <span class="mi">230</span><span class="p">);</span>

    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_red</span><span class="p">);</span>
    <span class="n">ez_draw_text</span>      <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_BL</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">260</span><span class="p">,</span> <span class="s">&quot;Fill&quot;</span><span class="p">);</span>
    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_yellow</span><span class="p">);</span>
    <span class="n">ez_fill_rectangle</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">160</span><span class="p">,</span> <span class="mi">270</span><span class="p">,</span> <span class="mi">220</span><span class="p">,</span> <span class="mi">310</span><span class="p">);</span>
    <span class="n">ez_fill_circle</span>    <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">240</span><span class="p">,</span> <span class="mi">270</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="mi">310</span><span class="p">);</span>
    <span class="n">ez_fill_triangle</span>  <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">320</span><span class="p">,</span> <span class="mi">270</span><span class="p">,</span> <span class="mi">380</span><span class="p">,</span> <span class="mi">280</span><span class="p">,</span> <span class="mi">350</span><span class="p">,</span> <span class="mi">310</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">XK_q</span> : <span class="n">ez_quit</span> <span class="p">();</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>

<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>                <span class="cm">/* Called by ez_main_loop() */</span>
<span class="p">{</span>                                                <span class="cm">/* for each event on win1   */</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>   : <span class="n">win1_on_expose</span>    <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyPress</span> : <span class="n">win1_on_key_press</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">320</span><span class="p">,</span> <span class="s">&quot;Demo 03: All drawings&quot;</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-03" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-03.png" />
</div>
</div>
<div class="section" id="displaying-text">
<span id="sec-tut-displaying-text"></span><span id="index-6"></span><h2>1.5. Displaying text<a class="headerlink" href="#displaying-text" title="Permalink to this headline">¶</a></h2>
<p>It is possible to draw text at any place in the window, thanks to
the function <a class="reference internal" href="ez-reference.html#c.ez_draw_text" title="ez_draw_text"><tt class="xref c c-func docutils literal"><span class="pre">ez_draw_text()</span></tt></a>. It takes as arguments: the window,
the kind of alignment <tt class="docutils literal"><span class="pre">align</span></tt>, the coordinates <tt class="docutils literal"><span class="pre">x1,y1</span></tt>,
finally a string to draw, or as in <tt class="docutils literal"><span class="pre">printf</span></tt>, a format and parameters.
Everything is detailed in section <a class="reference internal" href="ez-reference.html#sec-ref-fonts"><em>Text and fonts</em></a>.</p>
<p>The string can contain some <tt class="docutils literal"><span class="pre">\n</span></tt>, causing line breaks in the display.
The text drawing is performed in the current color, modifiable by
<a class="reference internal" href="ez-reference.html#c.ez_set_color" title="ez_set_color"><tt class="xref c c-func docutils literal"><span class="pre">ez_set_color()</span></tt></a>.</p>
<p>In the next example <a class="reference external" href="../../../demo-04.c">demo-04.c</a> we illustrate this, as well as the use of
<a class="reference internal" href="ez-reference.html#c.ez_window_get_size" title="ez_window_get_size"><tt class="xref c c-func docutils literal"><span class="pre">ez_window_get_size()</span></tt></a> to kindly adapt the drawing to the window
size changes.</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>


<span class="kt">void</span> <span class="nf">win1_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="n">w</span><span class="p">,</span> <span class="n">h</span><span class="p">;</span>

    <span class="n">ez_window_get_size</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">w</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">h</span><span class="p">);</span>

    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_black</span><span class="p">);</span>
    <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;=</span> <span class="mi">3</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">ez_set_nfont</span> <span class="p">(</span><span class="n">i</span><span class="p">);</span>
        <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TC</span><span class="p">,</span> <span class="n">w</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">h</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">25</span><span class="o">*</span><span class="p">(</span><span class="n">i</span><span class="o">-</span><span class="mi">2</span><span class="p">),</span> 
            <span class="s">&quot;Font number %d&quot;</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>                           <span class="cm">/* like a printf */</span>
    <span class="p">}</span>

    <span class="n">ez_set_nfont</span> <span class="p">(</span><span class="mi">0</span><span class="p">);</span>
    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_red</span><span class="p">);</span>

    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TL</span><span class="p">,</span>   <span class="mi">2</span><span class="p">,</span>   <span class="mi">1</span><span class="p">,</span> <span class="s">&quot;Top</span><span class="se">\n</span><span class="s">Left&quot;</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TC</span><span class="p">,</span> <span class="n">w</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span>   <span class="mi">1</span><span class="p">,</span> <span class="s">&quot;Top</span><span class="se">\n</span><span class="s">Center&quot;</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TR</span><span class="p">,</span> <span class="n">w</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span>   <span class="mi">1</span><span class="p">,</span> <span class="s">&quot;Top</span><span class="se">\n</span><span class="s">Right&quot;</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_ML</span><span class="p">,</span>   <span class="mi">2</span><span class="p">,</span> <span class="n">h</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="s">&quot;Middle</span><span class="se">\n</span><span class="s">Left&quot;</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_MR</span><span class="p">,</span> <span class="n">w</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="n">h</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="s">&quot;Middle</span><span class="se">\n</span><span class="s">Right&quot;</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_BL</span><span class="p">,</span>   <span class="mi">2</span><span class="p">,</span> <span class="n">h</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="s">&quot;Bottom</span><span class="se">\n</span><span class="s">Left&quot;</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_BC</span><span class="p">,</span> <span class="n">w</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">h</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="s">&quot;Bottom</span><span class="se">\n</span><span class="s">Center&quot;</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_BR</span><span class="p">,</span> <span class="n">w</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="n">h</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="s">&quot;Bottom</span><span class="se">\n</span><span class="s">Right&quot;</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">XK_q</span> : <span class="n">ez_quit</span> <span class="p">();</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>

<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>   : <span class="n">win1_on_expose</span>    <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyPress</span> : <span class="n">win1_on_key_press</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="s">&quot;Demo 04: Displaying text&quot;</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-04" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-04.png" />
</div>
</div>
<div class="section" id="tracing-events">
<span id="sec-tut-all-events"></span><span id="index-7"></span><h2>1.6. Tracing events<a class="headerlink" href="#tracing-events" title="Permalink to this headline">¶</a></h2>
<p>In the next example we list all possible events, and we trace in the terminal
the <tt class="docutils literal"><span class="pre">ev</span></tt> variable fields that are usable (the other ones are set to 0).
See also section <a class="reference internal" href="ez-reference.html#sec-ref-events"><em>Events</em></a>.</p>
<p>By default, the &#8220;Close&#8221; button in the title bar of one of the application
windows causes the termination of the program. We can change this behavior
by calling  <a class="reference internal" href="ez-reference.html#c.ez_auto_quit" title="ez_auto_quit"><tt class="xref c c-func docutils literal"><span class="pre">ez_auto_quit(0)</span></tt></a> :
from now on, the &#8220;Close&#8221; button will cause a <tt class="docutils literal"><span class="pre">WindowClose</span></tt> event, as in the
following example.</p>
<p>Here is the file <a class="reference external" href="../../../demo-05.c">demo-05.c</a> :</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>


<span class="kt">void</span> <span class="nf">win1_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>              <span class="cm">/* We must redraw everything */</span>
<span class="p">{</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_MC</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span> <span class="mi">150</span><span class="p">,</span> 
        <span class="s">&quot;Events are traced</span><span class="se">\n</span><span class="s">in the terminal.</span><span class="se">\n\n</span><span class="s">&quot;</span>
        <span class="s">&quot;Type &#39;q&#39; to quit.&quot;</span><span class="p">);</span>
    <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;Expose           win = 0x%x</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">ez_window_get_id</span><span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">));</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_button_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>             <span class="cm">/* Mouse button pressed */</span>
<span class="p">{</span>
    <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;ButtonPress      win = 0x%x  mx = %d  my = %d  mb = %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
        <span class="n">ez_window_get_id</span><span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">),</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">mx</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">my</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">mb</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_button_release</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>          <span class="cm">/* Mouse button released */</span>
<span class="p">{</span>
    <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;ButtonRelease    win = 0x%x  mx = %d  my = %d  mb = %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
        <span class="n">ez_window_get_id</span><span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">),</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">mx</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">my</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">mb</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_motion_notify</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>                     <span class="cm">/* Mouse moved */</span>
<span class="p">{</span>
    <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;MotionNotify     win = 0x%x  mx = %d  my = %d  mb = %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
        <span class="n">ez_window_get_id</span><span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">),</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">mx</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">my</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">mb</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>                         <span class="cm">/* Key pressed */</span>
<span class="p">{</span>
    <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;KeyPress         win = 0x%x  mx = %d  my = %d  &quot;</span>
            <span class="s">&quot;key_sym = 0x%x  key_name = %s  key_count = %d  key_string = </span><span class="se">\&quot;</span><span class="s">%s</span><span class="se">\&quot;\n</span><span class="s">&quot;</span><span class="p">,</span>
        <span class="n">ez_window_get_id</span><span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">),</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">mx</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">my</span><span class="p">,</span>
        <span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_name</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_count</span><span class="p">,</span>
        <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span> <span class="o">==</span> <span class="n">XK_Return</span> <span class="o">||</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span> <span class="o">==</span> <span class="n">XK_KP_Enter</span> <span class="o">?</span> <span class="s">&quot;&quot;</span> <span class="o">:</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_string</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_release</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>                      <span class="cm">/* Key released */</span>
<span class="p">{</span>
    <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;KeyRelease       win = 0x%x  mx = %d  my = %d  &quot;</span>
            <span class="s">&quot;key_sym = 0x%x  key_name = %s  key_count = %d  key_string = </span><span class="se">\&quot;</span><span class="s">%s</span><span class="se">\&quot;\n</span><span class="s">&quot;</span><span class="p">,</span>
        <span class="n">ez_window_get_id</span><span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">),</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">mx</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">my</span><span class="p">,</span>
        <span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_name</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_count</span><span class="p">,</span>
        <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span> <span class="o">==</span> <span class="n">XK_Return</span> <span class="o">||</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span> <span class="o">==</span> <span class="n">XK_KP_Enter</span> <span class="o">?</span> <span class="s">&quot;&quot;</span> <span class="o">:</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_string</span><span class="p">);</span>
     <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">XK_q</span> : <span class="n">ez_quit</span> <span class="p">();</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_configure_notify</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>          <span class="cm">/* Window size changed */</span>
<span class="p">{</span>
    <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;ConfigureNotify  win = 0x%x  width = %d  height = %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
        <span class="n">ez_window_get_id</span><span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">),</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">width</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">height</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_window_close</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>             <span class="cm">/* Close button pressed */</span>
<span class="p">{</span>
    <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;WindowClose      win = 0x%x</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">ez_window_get_id</span><span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">));</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>                <span class="cm">/* Called by ez_main_loop() */</span>
<span class="p">{</span>                                                <span class="cm">/* for each event on win1   */</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>          : <span class="n">win1_on_expose</span>           <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">ButtonPress</span>     : <span class="n">win1_on_button_press</span>     <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">ButtonRelease</span>   : <span class="n">win1_on_button_release</span>   <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">MotionNotify</span>    : <span class="n">win1_on_motion_notify</span>    <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyPress</span>        : <span class="n">win1_on_key_press</span>        <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyRelease</span>      : <span class="n">win1_on_key_release</span>      <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">ConfigureNotify</span> : <span class="n">win1_on_configure_notify</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">WindowClose</span>     : <span class="n">win1_on_window_close</span>     <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">default</span> <span class="o">:</span>
             <span class="n">printf</span> <span class="p">(</span><span class="s">&quot;Unknown event: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">);</span>
   <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="s">&quot;Demo 05: Tracing events&quot;</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>

    <span class="n">ez_auto_quit</span> <span class="p">(</span><span class="mi">0</span><span class="p">);</span>  <span class="cm">/* to get WindowClose event */</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-05" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-05.png" />
</div>
<p>Note: the <tt class="docutils literal"><span class="pre">TimerNotify</span></tt> events are not treated here, see  <a class="reference internal" href="ez-reference.html#sec-ref-timers"><em>Timers</em></a>.</p>
</div>
<div class="section" id="drawing-with-the-mouse">
<span id="sec-tut-drawing-with-mouse"></span><span id="index-8"></span><h2>1.7. Drawing with the mouse<a class="headerlink" href="#drawing-with-the-mouse" title="Permalink to this headline">¶</a></h2>
<p>The example shown in this section allows to draw a polygonal line with
the mouse. The coordinates of the vertices are stored in global variables
(we could also avoid global variables, see <a class="reference internal" href="ez-reference.html#sec-ref-client-data"><em>Client-data</em></a>).
Each time the mouse button is clicked, a new vertex is inserted;
for each mouse move with a pressed button (drag), the last vertex is moved.</p>
<p>By principle (and for technical reasons), the drawings must only be done
for the <tt class="docutils literal"><span class="pre">Expose</span></tt> event. If you want to update the drawings of a window for another
event, it is sufficient to send an <tt class="docutils literal"><span class="pre">Expose</span></tt> event using the function
<a class="reference internal" href="ez-reference.html#c.ez_send_expose" title="ez_send_expose"><tt class="xref c c-func docutils literal"><span class="pre">ez_send_expose()</span></tt></a>.
We do this here, for <tt class="docutils literal"><span class="pre">ButtonPress</span></tt>, <tt class="docutils literal"><span class="pre">MotionNotify</span></tt> and <tt class="docutils literal"><span class="pre">KeyPress</span></tt>
events.</p>
<p>Here is the file <a class="reference external" href="../../../demo-06.c">demo-06.c</a> :</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>

<span class="cp">#define VER_MAX 100</span>
<span class="kt">int</span> <span class="n">ver_nb</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">ver_x</span><span class="p">[</span><span class="n">VER_MAX</span><span class="p">],</span> <span class="n">ver_y</span><span class="p">[</span><span class="n">VER_MAX</span><span class="p">];</span>


<span class="kt">void</span> <span class="nf">vertex_clear</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="n">ver_nb</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">vertex_insert</span> <span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ver_nb</span> <span class="o">&gt;=</span> <span class="n">VER_MAX</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
    <span class="n">ver_x</span><span class="p">[</span><span class="n">ver_nb</span><span class="p">]</span> <span class="o">=</span> <span class="n">x</span><span class="p">;</span>
    <span class="n">ver_y</span><span class="p">[</span><span class="n">ver_nb</span><span class="p">]</span> <span class="o">=</span> <span class="n">y</span><span class="p">;</span>
    <span class="n">ver_nb</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">vertex_move</span> <span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ver_nb</span> <span class="o">&lt;=</span> <span class="mi">0</span> <span class="o">||</span> <span class="n">ver_nb</span> <span class="o">&gt;=</span> <span class="n">VER_MAX</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
    <span class="n">ver_x</span><span class="p">[</span><span class="n">ver_nb</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">x</span><span class="p">;</span>
    <span class="n">ver_y</span><span class="p">[</span><span class="n">ver_nb</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">y</span><span class="p">;</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">draw_vertices</span> <span class="p">(</span><span class="n">Ez_window</span> <span class="n">win</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span><span class="p">;</span>

    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_blue</span><span class="p">);</span>
    <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">ver_nb</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
        <span class="n">ez_draw_rectangle</span> <span class="p">(</span><span class="n">win</span><span class="p">,</span> <span class="n">ver_x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="n">ver_y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="n">ver_x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="mi">2</span><span class="p">,</span> <span class="n">ver_y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="mi">2</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">draw_segments</span> <span class="p">(</span><span class="n">Ez_window</span> <span class="n">win</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span><span class="p">;</span>

    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_grey</span><span class="p">);</span>
    <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">ver_nb</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
        <span class="n">ez_draw_line</span> <span class="p">(</span><span class="n">win</span><span class="p">,</span> <span class="n">ver_x</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">ver_y</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">ver_x</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">ver_y</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_black</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TL</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span>
        <span class="s">&quot;Click and drag the mouse in the window to draw.</span><span class="se">\n</span><span class="s">&quot;</span>
        <span class="s">&quot;Type Space to clear the window, &#39;q&#39; to quit.&quot;</span><span class="p">);</span>
    <span class="n">draw_segments</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span>
    <span class="n">draw_vertices</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_button_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">vertex_insert</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">mx</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">my</span><span class="p">);</span>
    <span class="n">ez_send_expose</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_motion_notify</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">mb</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>                            <span class="cm">/* No button pressed */</span>
    <span class="n">vertex_move</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">mx</span><span class="p">,</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">my</span><span class="p">);</span>
    <span class="n">ez_send_expose</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">XK_q</span> : 
            <span class="n">ez_quit</span> <span class="p">();</span> 
            <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">XK_space</span> : 
            <span class="n">vertex_clear</span> <span class="p">();</span>
            <span class="n">ez_send_expose</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span> 
            <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>       : <span class="n">win1_on_expose</span>        <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">ButtonPress</span>  : <span class="n">win1_on_button_press</span>  <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">MotionNotify</span> : <span class="n">win1_on_motion_notify</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyPress</span>     : <span class="n">win1_on_key_press</span>     <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="n">Ez_window</span> <span class="n">win1</span><span class="p">;</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">win1</span> <span class="o">=</span> <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="s">&quot;Demo 06: Drawing wih the mouse&quot;</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>

    <span class="cm">/* Enable double buffer to prevent window flashes */</span>
    <span class="n">ez_window_dbuf</span> <span class="p">(</span><span class="n">win1</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-06" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-06.png" />
</div>
</div>
<div class="section" id="managing-several-windows">
<span id="sec-tut-several-windows"></span><span id="index-9"></span><h2>1.8. Managing several windows<a class="headerlink" href="#managing-several-windows" title="Permalink to this headline">¶</a></h2>
<p>You can create as much windows that you want, by calling
<a class="reference internal" href="ez-reference.html#c.ez_window_create" title="ez_window_create"><tt class="xref c c-func docutils literal"><span class="pre">ez_window_create()</span></tt></a>. Each window that is created is immediately displayed
on top of the existing windows.
To destroy a window <tt class="docutils literal"><span class="pre">win</span></tt> (and thus hide it from screen),
use <a class="reference internal" href="ez-reference.html#c.ez_window_destroy" title="ez_window_destroy"><tt class="xref c c-func docutils literal"><span class="pre">ez_window_destroy(win)</span></tt></a>.</p>
<p>It is possible to hide a window  <tt class="docutils literal"><span class="pre">win</span></tt> (it still exists but is not displayed) by calling
<a class="reference internal" href="ez-reference.html#c.ez_window_show" title="ez_window_show"><tt class="xref c c-func docutils literal"><span class="pre">ez_window_show(win,</span> <span class="pre">0)</span></tt></a>, then show it again (on top of the
other ones) by calling <a class="reference internal" href="ez-reference.html#c.ez_window_show" title="ez_window_show"><tt class="xref c c-func docutils literal"><span class="pre">ez_window_show(win,</span> <span class="pre">1)</span></tt></a>.</p>
<p>In the next example, the main loop is configured by
<a class="reference internal" href="ez-reference.html#c.ez_auto_quit" title="ez_auto_quit"><tt class="xref c c-func docutils literal"><span class="pre">ez_auto_quit(0)</span></tt></a>,
which means that pressing the &#8220;Close&#8221; button of the window title bar will not end the
program, but send in place a <tt class="docutils literal"><span class="pre">WindowClose</span></tt> event.
According to the window involved, we hide the window, destroy the window
or exit the program.</p>
<p>Here is the file <a class="reference external" href="../../../demo-07.c">demo-07.c</a> :</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>

<span class="cm">/* Global variables */</span>
<span class="n">Ez_window</span> <span class="n">win1</span><span class="p">,</span> <span class="n">win2</span><span class="p">,</span> <span class="n">win3</span> <span class="o">=</span> <span class="n">None</span><span class="p">;</span> <span class="kt">int</span> <span class="n">show2</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>


<span class="kt">void</span> <span class="nf">win3_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TL</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span>
        <span class="s">&quot;If you close this window, it will be destroyed.&quot;</span><span class="p">);</span>
<span class="p">}</span>


<span class="cm">/* The user has clicked on the Close button of the window */</span>

<span class="kt">void</span> <span class="nf">win3_on_window_close</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">ev</span><span class="p">;</span>  <span class="cm">/* Tell the compiler that ev is unused */</span>
    <span class="n">ez_window_destroy</span> <span class="p">(</span><span class="n">win3</span><span class="p">);</span> <span class="n">win3</span> <span class="o">=</span> <span class="n">None</span><span class="p">;</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win3_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>      : <span class="n">win3_on_expose</span>       <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">WindowClose</span> : <span class="n">win3_on_window_close</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win2_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TL</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span>
        <span class="s">&quot;If you close this window, it will be hidden.&quot;</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win2_on_window_close</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">ev</span><span class="p">;</span>
    <span class="n">ez_window_show</span> <span class="p">(</span><span class="n">win2</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="n">show2</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win2_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>      : <span class="n">win2_on_expose</span>       <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">WindowClose</span> : <span class="n">win2_on_window_close</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TL</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span>
        <span class="s">&quot;Click in this window (to get the keyboard focus),</span><span class="se">\n</span><span class="s">&quot;</span>
        <span class="s">&quot;then type :</span><span class="se">\n</span><span class="s">&quot;</span>
        <span class="s">&quot;    - on &#39;m&#39; to show or hide window 2;</span><span class="se">\n</span><span class="s">&quot;</span>
        <span class="s">&quot;    - on &#39;c&#39; to create or destroy window 3;</span><span class="se">\n</span><span class="s">&quot;</span>
        <span class="s">&quot;    - on &#39;q&#39; to quit.</span><span class="se">\n</span><span class="s">&quot;</span>
        <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span>
        <span class="s">&quot;If you close this window, the program will end.&quot;</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">XK_q</span> : <span class="n">ez_quit</span> <span class="p">();</span> <span class="k">break</span><span class="p">;</span>

        <span class="k">case</span> <span class="n">XK_m</span> :
            <span class="n">show2</span> <span class="o">=</span> <span class="o">!</span><span class="n">show2</span><span class="p">;</span>                       <span class="cm">/* show or hide the window */</span>
            <span class="n">ez_window_show</span> <span class="p">(</span><span class="n">win2</span><span class="p">,</span> <span class="n">show2</span><span class="p">);</span>
        <span class="k">break</span><span class="p">;</span>

        <span class="k">case</span> <span class="n">XK_c</span> :
            <span class="k">if</span> <span class="p">(</span><span class="n">win3</span> <span class="o">==</span> <span class="n">None</span><span class="p">)</span>      <span class="cm">/* if the window doesn&#39;t exist, create it */</span>
                <span class="n">win3</span> <span class="o">=</span> <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">380</span><span class="p">,</span> <span class="mi">220</span><span class="p">,</span> <span class="s">&quot;Window 3&quot;</span><span class="p">,</span> <span class="n">win3_on_event</span><span class="p">);</span>
            <span class="k">else</span> <span class="p">{</span> <span class="n">ez_window_destroy</span> <span class="p">(</span><span class="n">win3</span><span class="p">);</span> <span class="n">win3</span> <span class="o">=</span> <span class="n">None</span><span class="p">;</span> <span class="p">}</span>
        <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_window_close</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">ev</span><span class="p">;</span>
    <span class="n">ez_quit</span> <span class="p">();</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>      : <span class="n">win1_on_expose</span>       <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyPress</span>    : <span class="n">win1_on_key_press</span>    <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">WindowClose</span> : <span class="n">win1_on_window_close</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">win1</span> <span class="o">=</span> <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="s">&quot;Demo 07: Several windows&quot;</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>
    <span class="n">win2</span> <span class="o">=</span> <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span> <span class="s">&quot;Window 2&quot;</span><span class="p">,</span> <span class="n">win2_on_event</span><span class="p">);</span>
    <span class="n">ez_window_show</span> <span class="p">(</span><span class="n">win2</span><span class="p">,</span> <span class="n">show2</span><span class="p">);</span>

    <span class="cm">/* By default, closing any window will cause the end of the program.</span>
<span class="cm">       We change this behaviour: for now on, closing any window will send </span>
<span class="cm">       a WindowClose event for this window. */</span>
    <span class="n">ez_auto_quit</span> <span class="p">(</span><span class="mi">0</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-07" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-07.png" />
</div>
</div>
<div class="section" id="text-input">
<span id="sec-tut-text-input"></span><span id="index-10"></span><h2>1.9. Text input<a class="headerlink" href="#text-input" title="Permalink to this headline">¶</a></h2>
<p>The next example <a class="reference external" href="../../../demo-08.c">demo-08.c</a> demonstrates how to read a string on keyboard,
suppress some characters using the Backspace, and detect the Enter key
to trigger an action.</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>

<span class="cp">#define BUF_MAX 80</span>
<span class="kt">char</span> <span class="n">buf1</span><span class="p">[</span><span class="n">BUF_MAX</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;&quot;</span><span class="p">,</span> <span class="n">buf2</span><span class="p">[</span><span class="n">BUF_MAX</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;&quot;</span><span class="p">;</span>


<span class="cm">/* Return 1 if text must be displayed again, 2 if text is validated, else 0 */</span>

<span class="kt">int</span> <span class="nf">text_input</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">s</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span><span class="p">;</span>

    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>

        <span class="k">case</span> <span class="n">XK_BackSpace</span> :                                 <span class="cm">/* Backspace key */</span>
            <span class="n">i</span> <span class="o">=</span> <span class="n">strlen</span> <span class="p">(</span><span class="n">s</span><span class="p">);</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
            <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
            <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>

        <span class="k">case</span> <span class="n">XK_Return</span> :                                        <span class="cm">/* Enter key */</span>
            <span class="k">return</span> <span class="mi">2</span><span class="p">;</span>

        <span class="k">default</span> <span class="o">:</span>                                      <span class="cm">/* Insert a character */</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_count</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
            <span class="n">i</span> <span class="o">=</span> <span class="n">strlen</span> <span class="p">(</span><span class="n">s</span><span class="p">);</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">&gt;=</span> <span class="n">BUF_MAX</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
            <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_string</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span> <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
            <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">text_display</span> <span class="p">(</span><span class="n">Ez_window</span> <span class="n">win</span><span class="p">,</span> <span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="n">y</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">s1</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">s2</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_black</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TL</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s">&quot;Text: %s_&quot;</span><span class="p">,</span> <span class="n">s1</span><span class="p">);</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">strcmp</span> <span class="p">(</span><span class="n">buf2</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_blue</span><span class="p">);</span>
        <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_TC</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span>
            <span class="s">&quot;You have validated this text:</span><span class="se">\n</span><span class="s">%s&quot;</span><span class="p">,</span> <span class="n">s2</span><span class="p">);</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">text_display</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="n">buf1</span><span class="p">,</span> <span class="n">buf2</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="n">text_input</span> <span class="p">(</span><span class="n">ev</span><span class="p">,</span> <span class="n">buf1</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">k</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span> <span class="n">strncpy</span> <span class="p">(</span><span class="n">buf2</span><span class="p">,</span> <span class="n">buf1</span><span class="p">,</span> <span class="n">BUF_MAX</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">k</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">ez_send_expose</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>   : <span class="n">win1_on_expose</span>    <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyPress</span> : <span class="n">win1_on_key_press</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">ez_window_create</span> <span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span> <span class="s">&quot;Demo 08: Text input&quot;</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-08" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-08.png" />
</div>
</div>
<div class="section" id="animations">
<span id="sec-tut-animations"></span><span id="index-11"></span><h2>1.10. Animations<a class="headerlink" href="#animations" title="Permalink to this headline">¶</a></h2>
<p>To perform animations, two additional ingredients are needed:
a timer (see <a class="reference internal" href="ez-reference.html#sec-ref-timers"><em>Timers</em></a>) to maintain the temporal sequence,
and double buffering (see <a class="reference internal" href="ez-reference.html#sec-ref-dbuf"><em>Double buffering</em></a>) to prevent display
flashing.</p>
<dl class="docutils">
<dt>Warning:</dt>
<dd>Never ever employ <tt class="docutils literal"><span class="pre">sleep</span></tt> or <tt class="docutils literal"><span class="pre">usleep</span></tt>, because
these functions prevent the callbacks to restore the control to <a class="reference internal" href="ez-reference.html#c.ez_main_loop" title="ez_main_loop"><tt class="xref c c-func docutils literal"><span class="pre">ez_main_loop()</span></tt></a>,
and thus they freeze the display and the interface (or at least
severely disrupt them).</dd>
</dl>
<p>The principle of an animation is the following:</p>
<ul class="simple">
<li>start a timer in <tt class="docutils literal"><span class="pre">main</span></tt>, which will cause a <tt class="docutils literal"><span class="pre">TimerNotify</span></tt> event
few milliseconds later;</li>
</ul>
<ul class="simple">
<li>upon receipt of this <tt class="docutils literal"><span class="pre">TimerNotify</span></tt> event in the window callback,
we do three things:<ul>
<li>we increment a counter (or coordinates, or whatever) in order to change the
position of the object to animate;</li>
<li>we send an <tt class="docutils literal"><span class="pre">Expose</span></tt> event to refresh display;</li>
<li>last, we restart the timer such that there will be a next <tt class="docutils literal"><span class="pre">TimerNotify</span></tt>
event (what we obtain is a kind of timed loop of <tt class="docutils literal"><span class="pre">TimerNotify</span></tt> events);</li>
</ul>
</li>
</ul>
<ul class="simple">
<li>each time an <tt class="docutils literal"><span class="pre">Expose</span></tt> event is received, we redraw the window content
tacking account of the counter (or the coordinates) to draw the animated
object in its current position. Never draw for another event, you would
disturb the double display buffer.
Moreover, EZ-Draw optimize displaying by eliminating useless  <tt class="docutils literal"><span class="pre">Expose</span></tt>
events.</li>
</ul>
<p>Here is a first example <a class="reference external" href="../../../demo-09.c">demo-09.c</a> below. The animation shows a growing circle
at the middle of the window; it also adapts the drawings to the window size
changes.</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>

<span class="cp">#define MAX_CPT1 100</span>

<span class="cm">/* We can avoid global variables by using ez_set_data(), see demo-10.c</span>
<span class="cm">   and the next examples */</span>
<span class="kt">int</span> <span class="n">count1</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">win1_w</span> <span class="o">=</span> <span class="mi">300</span><span class="p">,</span> <span class="n">win1_h</span> <span class="o">=</span> <span class="mi">200</span><span class="p">,</span> <span class="n">delay1</span> <span class="o">=</span> <span class="mi">30</span><span class="p">;</span>


<span class="kt">void</span> <span class="nf">win1_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="cm">/* We draw based on count1 */</span>
    <span class="kt">int</span> <span class="n">xc</span> <span class="o">=</span> <span class="n">win1_w</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">rx</span> <span class="o">=</span> <span class="n">xc</span> <span class="o">*</span> <span class="n">count1</span> <span class="o">/</span> <span class="n">MAX_CPT1</span><span class="p">,</span>
        <span class="n">yc</span> <span class="o">=</span> <span class="n">win1_h</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">ry</span> <span class="o">=</span> <span class="n">yc</span> <span class="o">*</span> <span class="n">count1</span> <span class="o">/</span> <span class="n">MAX_CPT1</span><span class="p">;</span>

    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_magenta</span><span class="p">);</span> 
    <span class="n">ez_set_thick</span> <span class="p">(</span><span class="mi">3</span><span class="p">);</span>
    <span class="n">ez_draw_circle</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">xc</span><span class="o">-</span><span class="n">rx</span><span class="p">,</span> <span class="n">yc</span><span class="o">-</span><span class="n">ry</span><span class="p">,</span> <span class="n">xc</span><span class="o">+</span><span class="n">rx</span><span class="p">,</span> <span class="n">yc</span><span class="o">+</span><span class="n">ry</span><span class="p">);</span>

    <span class="n">ez_set_color</span> <span class="p">(</span><span class="n">ez_black</span><span class="p">);</span> <span class="n">ez_set_nfont</span> <span class="p">(</span><span class="mi">0</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">EZ_BL</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="n">win1_h</span><span class="o">-</span><span class="mi">8</span><span class="p">,</span> <span class="s">&quot;q: quit&quot;</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">XK_q</span> : <span class="n">ez_quit</span> <span class="p">();</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_configure_notify</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">win1_w</span> <span class="o">=</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">width</span><span class="p">;</span> <span class="n">win1_h</span> <span class="o">=</span> <span class="n">ev</span><span class="o">-&gt;</span><span class="n">height</span><span class="p">;</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_timer_notify</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>            <span class="cm">/* The timer has expired */</span>
<span class="p">{</span>
    <span class="cm">/* We increment the counter count1 so as to modify the position of the</span>
<span class="cm">       object to animate */</span>
    <span class="n">count1</span> <span class="o">=</span> <span class="p">(</span><span class="n">count1</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">%</span> <span class="n">MAX_CPT1</span><span class="p">;</span>
    <span class="cm">/* We send an Expose event so that the window will be displayed again */</span>
    <span class="n">ez_send_expose</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span>
    <span class="cm">/* We restart the timer to maintain a &quot;loop&quot; or TimerNotify events,</span>
<span class="cm">       which is iterated each delay1 milliseconds */</span>
    <span class="n">ez_start_timer</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">,</span> <span class="n">delay1</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>          : <span class="n">win1_on_expose</span>           <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyPress</span>        : <span class="n">win1_on_key_press</span>        <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">ConfigureNotify</span> : <span class="n">win1_on_configure_notify</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">TimerNotify</span>     : <span class="n">win1_on_timer_notify</span>     <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
<span class="p">{</span>
    <span class="n">Ez_window</span> <span class="n">win1</span><span class="p">;</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">win1</span> <span class="o">=</span> <span class="n">ez_window_create</span> <span class="p">(</span><span class="n">win1_w</span><span class="p">,</span> <span class="n">win1_h</span><span class="p">,</span> <span class="s">&quot;Demo 09: Hypnosis&quot;</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>

    <span class="cm">/* Enable double buffer to prevent window flashes */</span>
    <span class="n">ez_window_dbuf</span> <span class="p">(</span><span class="n">win1</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>

    <span class="cm">/* Start a timer to get a TimerNotify event in delay1 milliseconds:</span>
<span class="cm">       this is the starting point of the &quot;loop&quot; of TimerNotify events. */</span>
    <span class="n">ez_start_timer</span> <span class="p">(</span><span class="n">win1</span><span class="p">,</span> <span class="n">delay1</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-09" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-09.png" />
</div>
<p>Another example is provided by <a class="reference external" href="../../../demo-10.c">demo-10.c</a> to illustrate multiple animations:
in one window we turn the hands of a watch (type space for pause),
while in another window a ball is bouncing on a racket (the window can be
enlarged).</p>
<p>These windows are obtained:</p>
<div class="centrer container">
<img alt="demo-10-1" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-10-1.png" />
<img alt="demo-10-2" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-10-2.png" />
</div>
<p>This example <a class="reference external" href="../../../demo-10.c">demo-10.c</a> demonstrates also how to attach an information
(e.g. a  <tt class="docutils literal"><span class="pre">struct</span></tt>) to a window, so as to avoid global variables.
For more explanations, see <a class="reference internal" href="ez-reference.html#sec-ref-client-data"><em>Client-data</em></a>.
We use this possibility in the whole next part.</p>
</div>
<div class="section" id="images">
<span id="sec-tut-images"></span><span id="index-12"></span><h2>1.11. Images<a class="headerlink" href="#images" title="Permalink to this headline">¶</a></h2>
<p>In the previous sections we have seen what we can do with the basic module.</p>
<p>EZ-Draw comes with a second module, <a class="reference external" href="../../../ez-image.c">ez-image.c</a>,
that allows to load and display color images in PNG, JPEG, GIF or BMP format,
or create an image in memory and draw into.
These possibilities are detailed in sections <a class="reference internal" href="ez-reference.html#sec-ref-images-type"><em>The image type</em></a>
and following.</p>
<p>To use this module, just include <a class="reference external" href="../../../ez-image.h">ez-image.h</a>.
Here is the example <a class="reference external" href="../../../demo-13.c">demo-13.c</a> where we get a file name as  argument of the
command line, then we load the image and display it:</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>
<span class="cp">#include &quot;ez-image.h&quot;</span>


<span class="k">typedef</span> <span class="k">struct</span> <span class="p">{</span>
    <span class="n">Ez_image</span> <span class="o">*</span><span class="n">image1</span><span class="p">;</span>
    <span class="n">Ez_window</span> <span class="n">win1</span><span class="p">;</span>
<span class="p">}</span> <span class="n">App_data</span><span class="p">;</span>


<span class="kt">void</span> <span class="nf">app_data_init</span> <span class="p">(</span><span class="n">App_data</span> <span class="o">*</span><span class="n">a</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">filename</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span> <span class="o">=</span> <span class="n">ez_image_load</span> <span class="p">(</span><span class="n">filename</span><span class="p">);</span>                   <span class="cm">/* Load an image */</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="n">exit</span> <span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">app_data_destroy</span> <span class="p">(</span><span class="n">App_data</span> <span class="o">*</span><span class="n">a</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">ez_image_destroy</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span><span class="p">);</span>                           <span class="cm">/* Destroy image */</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">App_data</span> <span class="o">*</span><span class="n">a</span> <span class="o">=</span> <span class="n">ez_get_data</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span>

    <span class="n">ez_image_paint</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">win1</span><span class="p">,</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>              <span class="cm">/* Display image */</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">XK_q</span> : <span class="n">ez_quit</span> <span class="p">();</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>   : <span class="n">win1_on_expose</span>    <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyPress</span> : <span class="n">win1_on_key_press</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
    <span class="kt">char</span> <span class="o">*</span><span class="n">filename</span> <span class="o">=</span> <span class="s">&quot;images/tux2.gif&quot;</span><span class="p">;</span>
    <span class="n">App_data</span> <span class="n">a</span><span class="p">;</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">argc</span><span class="o">-</span><span class="mi">1</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">)</span>
         <span class="n">fprintf</span> <span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Usage: %s image</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
    <span class="k">else</span> <span class="n">filename</span> <span class="o">=</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span> <span class="p">(</span><span class="mi">1</span><span class="p">);</span>
    <span class="n">app_data_init</span> <span class="p">(</span><span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">filename</span><span class="p">);</span>

    <span class="n">a</span><span class="p">.</span><span class="n">win1</span> <span class="o">=</span> <span class="n">ez_window_create</span> <span class="p">(</span>                   <span class="cm">/* Resize window for image */</span>
        <span class="n">a</span><span class="p">.</span><span class="n">image1</span><span class="o">-&gt;</span><span class="n">width</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">image1</span><span class="o">-&gt;</span><span class="n">height</span><span class="p">,</span> 
        <span class="n">filename</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>
    <span class="n">ez_set_data</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">win1</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">);</span>
    <span class="n">ez_window_dbuf</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">win1</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>

    <span class="n">app_data_destroy</span> <span class="p">(</span><span class="o">&amp;</span><span class="n">a</span><span class="p">);</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-13" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-13.png" />
</div>
<p id="index-13">To compile this file <tt class="docutils literal"><span class="pre">demo-13.c</span></tt> on Unix, type:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">gcc -Wall demo-13.c ez-draw.c ez-image.c -o demo-13 -lX11 -lXext -lm</span>
</pre></div>
</div>
<p>or on Windows, type:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">gcc -Wall demo-13.c ez-draw.c ez-image.c -o demo-13.exe -lgdi32 -lmsimg32 -lm</span>
</pre></div>
</div>
<p>You can also append the executable file name at the end of <tt class="docutils literal"><span class="pre">EXECS_IM</span> <span class="pre">=</span></tt>
in the <a class="reference external" href="../../../Makefile">Makefile</a>; then type <tt class="docutils literal"><span class="pre">make</span> <span class="pre">all</span></tt> to compile.</p>
<p>The formats PNG, GIF and BMP allow to store a transparency level, in what is
called the alpha channel. The formats GIF and BMP store the alpha channel
over 1 bit; the pixels are either transparent (0), or opaque (255).
The PNG format stores the alpha channel over 8 bits (from 0 for transparent,
to 255 for opaque).</p>
<p>The module <tt class="docutils literal"><span class="pre">ez-image</span></tt> is able to display an image by taking in account
the transparency, using an opacity threshold on the alpha channel:
the pixels are either opaques (displayed) or transparents (not displayed).</p>
<p>The next example <a class="reference external" href="../../../demo-14.c">demo-14.c</a> gets two file names as arguments of the command line,
then superimpose both images.
You can move the second image using arrow keys, or change the opacity threshold
using keys <tt class="docutils literal"><span class="pre">+</span></tt> and <tt class="docutils literal"><span class="pre">-</span></tt>.</p>
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &quot;ez-draw.h&quot;</span>
<span class="cp">#include &quot;ez-image.h&quot;</span>


<span class="k">typedef</span> <span class="k">struct</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">i2_x</span><span class="p">,</span> <span class="n">i2_y</span><span class="p">;</span>
    <span class="n">Ez_image</span> <span class="o">*</span><span class="n">image1</span><span class="p">,</span> <span class="o">*</span><span class="n">image2</span><span class="p">;</span>
    <span class="n">Ez_window</span> <span class="n">win1</span><span class="p">;</span>
<span class="p">}</span> <span class="n">App_data</span><span class="p">;</span>


<span class="kt">void</span> <span class="nf">app_data_init</span> <span class="p">(</span><span class="n">App_data</span> <span class="o">*</span><span class="n">a</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">filename1</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">filename2</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span> <span class="o">=</span> <span class="n">ez_image_load</span> <span class="p">(</span><span class="n">filename1</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="n">exit</span> <span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="n">a</span><span class="o">-&gt;</span><span class="n">image2</span> <span class="o">=</span> <span class="n">ez_image_load</span> <span class="p">(</span><span class="n">filename2</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">image2</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="n">exit</span> <span class="p">(</span><span class="mi">1</span><span class="p">);</span>

    <span class="cm">/* Initial position is centered */</span>
    <span class="n">a</span><span class="o">-&gt;</span><span class="n">i2_x</span> <span class="o">=</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span><span class="o">-&gt;</span><span class="n">width</span>  <span class="o">-</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">image2</span><span class="o">-&gt;</span><span class="n">width</span> <span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
    <span class="n">a</span><span class="o">-&gt;</span><span class="n">i2_y</span> <span class="o">=</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span><span class="o">-&gt;</span><span class="n">height</span> <span class="o">-</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">image2</span><span class="o">-&gt;</span><span class="n">height</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">app_data_destroy</span> <span class="p">(</span><span class="n">App_data</span> <span class="o">*</span><span class="n">a</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">ez_image_destroy</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span><span class="p">);</span>
    <span class="n">ez_image_destroy</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">image2</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_expose</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">App_data</span> <span class="o">*</span><span class="n">a</span> <span class="o">=</span> <span class="n">ez_get_data</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span>

    <span class="n">ez_image_paint</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">win1</span><span class="p">,</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
    <span class="n">ez_image_paint</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">win1</span><span class="p">,</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">image2</span><span class="p">,</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">i2_x</span><span class="p">,</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">i2_y</span><span class="p">);</span> 
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">win1</span><span class="p">,</span> <span class="n">EZ_BLF</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span><span class="o">-&gt;</span><span class="n">height</span><span class="o">+</span><span class="mi">15</span><span class="p">,</span> 
        <span class="s">&quot;[Arrows] to move&quot;</span><span class="p">);</span>
    <span class="n">ez_draw_text</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">win1</span><span class="p">,</span> <span class="n">EZ_BRF</span><span class="p">,</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span><span class="o">-&gt;</span><span class="n">width</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">image1</span><span class="o">-&gt;</span><span class="n">height</span><span class="o">+</span><span class="mi">15</span><span class="p">,</span> 
        <span class="s">&quot;Opacity [+-] : %d&quot;</span><span class="p">,</span> <span class="n">a</span><span class="o">-&gt;</span><span class="n">image2</span><span class="o">-&gt;</span><span class="n">opacity</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_key_press</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">App_data</span> <span class="o">*</span><span class="n">a</span> <span class="o">=</span> <span class="n">ez_get_data</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">win</span><span class="p">);</span>

    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">key_sym</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">XK_q</span> : <span class="n">ez_quit</span> <span class="p">();</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">XK_Left</span>        : 
        <span class="k">case</span> <span class="n">XK_KP_Left</span>     : <span class="n">a</span><span class="o">-&gt;</span><span class="n">i2_x</span><span class="o">--</span> <span class="p">;</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">XK_Right</span>       :
        <span class="k">case</span> <span class="n">XK_KP_Right</span>    : <span class="n">a</span><span class="o">-&gt;</span><span class="n">i2_x</span><span class="o">++</span> <span class="p">;</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">XK_Up</span>          : 
        <span class="k">case</span> <span class="n">XK_KP_Up</span>       : <span class="n">a</span><span class="o">-&gt;</span><span class="n">i2_y</span><span class="o">--</span> <span class="p">;</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">XK_Down</span>        : 
        <span class="k">case</span> <span class="n">XK_KP_Down</span>     : <span class="n">a</span><span class="o">-&gt;</span><span class="n">i2_y</span><span class="o">++</span> <span class="p">;</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">XK_minus</span>       :
        <span class="k">case</span> <span class="n">XK_KP_Subtract</span> : <span class="n">a</span><span class="o">-&gt;</span><span class="n">image2</span><span class="o">-&gt;</span><span class="n">opacity</span><span class="o">--</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">XK_plus</span>        :
        <span class="k">case</span> <span class="n">XK_KP_Add</span>      : <span class="n">a</span><span class="o">-&gt;</span><span class="n">image2</span><span class="o">-&gt;</span><span class="n">opacity</span><span class="o">++</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">default</span>             <span class="o">:</span> <span class="k">return</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">ez_send_expose</span> <span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">win1</span><span class="p">);</span>
<span class="p">}</span>


<span class="kt">void</span> <span class="nf">win1_on_event</span> <span class="p">(</span><span class="n">Ez_event</span> <span class="o">*</span><span class="n">ev</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">switch</span> <span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">type</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="n">Expose</span>   : <span class="n">win1_on_expose</span>    <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
        <span class="k">case</span> <span class="n">KeyPress</span> : <span class="n">win1_on_key_press</span> <span class="p">(</span><span class="n">ev</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="kt">int</span> <span class="nf">main</span> <span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
    <span class="kt">char</span> <span class="o">*</span><span class="n">file1</span> <span class="o">=</span> <span class="s">&quot;images/paper1.jpg&quot;</span><span class="p">,</span> <span class="o">*</span><span class="n">file2</span> <span class="o">=</span> <span class="s">&quot;images/tux1.png&quot;</span><span class="p">;</span>
    <span class="n">App_data</span> <span class="n">a</span><span class="p">;</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">argc</span><span class="o">-</span><span class="mi">1</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">)</span>
        <span class="n">fprintf</span> <span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Usage: %s image1 image2</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
    <span class="k">else</span> <span class="p">{</span> <span class="n">file1</span> <span class="o">=</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span> <span class="n">file2</span> <span class="o">=</span> <span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span> <span class="p">}</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">ez_init</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
    <span class="n">app_data_init</span> <span class="p">(</span><span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">file1</span><span class="p">,</span> <span class="n">file2</span><span class="p">);</span>

    <span class="n">a</span><span class="p">.</span><span class="n">win1</span> <span class="o">=</span> <span class="n">ez_window_create</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">image1</span><span class="o">-&gt;</span><span class="n">width</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">image1</span><span class="o">-&gt;</span><span class="n">height</span><span class="o">+</span><span class="mi">15</span><span class="p">,</span> 
        <span class="s">&quot;Demo 14: Images with transparency&quot;</span><span class="p">,</span> <span class="n">win1_on_event</span><span class="p">);</span>
    <span class="n">ez_set_data</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">win1</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">);</span>
    <span class="n">ez_window_dbuf</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">win1</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>

    <span class="n">ez_main_loop</span> <span class="p">();</span>

    <span class="n">app_data_destroy</span> <span class="p">(</span><span class="o">&amp;</span><span class="n">a</span><span class="p">);</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-14" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-14.png" />
</div>
<p>It is also possible to create an image in memory, then set the pixels colors.
The example <a class="reference external" href="../../../demo-12.c">demo-12.c</a> displays the HSV palette computed in this manner.</p>
<p>This window is obtained:</p>
<div class="centrer container">
<img alt="demo-12" src="http://pageperso.lif.univ-mrs.fr/~edouard.thiel/snap-EZ-Draw-1.2/snap-demo-12.png" />
</div>
<p>You will find more informations about images in the <a class="reference internal" href="ez-reference.html#chap-ref-manual"><em>Reference manual</em></a>.</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper"><p class="quicklinks">
  <a href="../../../index-en.html">Back</a> |
  <a href="#">Up</a> |
  <a href="#endpage">Down</a>
</p>
<h3><a href="ez-manual.html">Table Of Contents</a></h3>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="">1. Tutorial</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#first-program-with-a-window">1.1. First program with a window</a></li>
<li class="toctree-l2"><a class="reference internal" href="#compilation">1.2. Compilation</a></li>
<li class="toctree-l2"><a class="reference internal" href="#event-handler">1.3. Event handler</a></li>
<li class="toctree-l2"><a class="reference internal" href="#drawings-and-colors">1.4. Drawings and colors</a></li>
<li class="toctree-l2"><a class="reference internal" href="#displaying-text">1.5. Displaying text</a></li>
<li class="toctree-l2"><a class="reference internal" href="#tracing-events">1.6. Tracing events</a></li>
<li class="toctree-l2"><a class="reference internal" href="#drawing-with-the-mouse">1.7. Drawing with the mouse</a></li>
<li class="toctree-l2"><a class="reference internal" href="#managing-several-windows">1.8. Managing several windows</a></li>
<li class="toctree-l2"><a class="reference internal" href="#text-input">1.9. Text input</a></li>
<li class="toctree-l2"><a class="reference internal" href="#animations">1.10. Animations</a></li>
<li class="toctree-l2"><a class="reference internal" href="#images">1.11. Images</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="ez-reference.html">2. Reference manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="ez-install.html">3. Installation</a></li>
</ul>
<h3 class="indexlink">
  <a href="genindex.html#">Index</a>
</h3>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <span class="current">English</span></li>
        <li class="right">
          <a href="../../fr/html/ez-tutorial.html">Français</a> |</li>
        <li><a href="../../../index-en.html">EZ-Draw 1.2</a> &raquo;</li>
        <li><a href="ez-manual.html">Documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2014, Edouard Thiel.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.2.
    </div>
    <a name="endpage"></a>
  </body>
</html>